export default {
  namespaced: true,

  state: () => ({
    token: uni.getStorageSync('token')|| '',
    nickname : uni.getStorageSync('nickname') || '',
    personSignature : uni.getStorageSync('preSignature')|| '',
    avatarUrl :uni.getStorageSync('avatarUrl')|| '',
    gender: uni.getStorageSync('gender'),
    role: uni.getStorageSync('role'),
  }),
  mutations: {
    updateNickname(state, nickname){
      state.nickname = nickname
      console.log(state.nickname);
      this.commit('my_user/saveNickname')
    },
    saveNickname(state){
      uni.setStorageSync('nickname', state.nickname)
    },
    updateRole(state, role){
      state.role = role;
      this.commit('my_user/saveRole')
    },
    saveRole(state){
      uni.setStorageSync('role', state.role)
    },
    updateToken(state, token){
      state.token = token
      this.commit('my_user/saveToken')
    },
    saveToken(state){
      uni.setStorageSync('token',state.token)
    },
    updatePreSignature(state, preSignature){
      state.personSignature = preSignature
      this.commit('my_user/savePerSignature')
    },
    savePerSignature(state){
      uni.setStorageSync('preSignature',state.personSignature)
    },
    updateAvatarUrl(state, avatarUrl){
      state.avatarUrl = avatarUrl
      this.commit('my_user/saveAvatarUrl')
    },
    saveAvatarUrl(state){
      uni.setStorageSync('avatarUrl',state.avatarUrl)
    },
    updateGender(state, gender){
      state.gender = gender
      this.commit('my_user/saveGender')
    },
    saveGender(state){
      uni.setStorageSync('gender',state.gender)
    }
  },
  getters :{
    getToken(state){
      console.log(state.token);
      return state.token
    },
    getSignature(state){
      if(!state.personSignature) return ' '
      return state.personSignature
    },
    getNickname(state){
      if(!state.nickname) return ' '
      return state.nickname
    },
    getAvatarUrl(state){
      if(!state.avatarUrl) return ' '
      return state.avatarUrl
    },
    getGender(state){
      if(!state.gender) return 0
      return state.gender
    }
  }
}
